package com.jr.util;

import java.io.IOException;
import java.sql.*;

public class DBHelper {
    public static void main(String[] args) throws SQLException, IOException, ClassNotFoundException {
        getconn();
    }

    //获得连接
    public static Connection getconn() throws IOException, ClassNotFoundException, SQLException {

        Class.forName("com.mysql.cj.jdbc.Driver");
        Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/financial_payment_management_system?serverTimezone=GMT", "root", "111111");

        return con;
    }


    //关闭连接
    public static void closeAll(ResultSet rs, PreparedStatement ps, Connection con) {
            if (rs != null) {
                try {
                    rs.close();
                } catch (SQLException e) {
                    e.printStackTrace();
                }
            }

            if (ps != null) {
                try {
                    ps.close();
                } catch (SQLException e) {
                    e.printStackTrace();
                }
            }

            if (con != null) {
                try {
                    con.close();
                } catch (SQLException e) {
                    e.printStackTrace();
                }
            }
    }

    public static void SIUD(String sql, Object... obj) throws SQLException, IOException, ClassNotFoundException {

//        try {
            Connection getconn = DBHelper.getconn();
            PreparedStatement ps = getconn.prepareStatement(sql);
            for (int i = 1; i <= obj.length + 1; i++) {
                ps.setObject(i, obj[i - 1]);
            }
//            if(sql.)
//            ResultSet rs = ps.executeQuery();
//

//        }
    }
}


